#include "Int_Key.h"

Key_Type Int_Key_Scan()
{
    if (READ_KEY_LEFT == 0) {
        vTaskDelay(10);
        if (READ_KEY_LEFT == 0) {
            while (READ_KEY_LEFT == 0);
            return KEY_LEFT;
        }
    }
    if (READ_KEY_RIGHT == 0) {
        vTaskDelay(10);
        if (READ_KEY_RIGHT == 0) {
            while (READ_KEY_RIGHT == 0);
            return KEY_RIGHT;
        }
    }
    if (READ_KEY_UP == 0) {
        vTaskDelay(10);
        if (READ_KEY_UP == 0) {
            while (READ_KEY_UP == 0);
            return KEY_UP;
        }
    }
    if (READ_KEY_DOWN == 0) {
        vTaskDelay(10);
        if (READ_KEY_DOWN == 0) {
            while (READ_KEY_DOWN == 0);
            return KEY_DOWN;
        }
    }
    if (READ_KEY_LEFT_X == 0) {
        uint32_t tick_count = xTaskGetTickCount();
        vTaskDelay(10);
        if (READ_KEY_LEFT_X == 0) {
            while (READ_KEY_LEFT_X == 0);
            if (xTaskGetTickCount() - tick_count > 500) {
                return KEY_LEFT_X_LONG;
            } else {
                return KEY_LEFT_X;
            }
        }
    }
    if (READ_KEY_RIGHT_X == 0) {
        uint32_t tick_count = xTaskGetTickCount();
        vTaskDelay(10);
        if (READ_KEY_RIGHT_X == 0) {
            while (READ_KEY_RIGHT_X == 0);
            if (xTaskGetTickCount() - tick_count > 500) {
                return KEY_RIGHT_X_LONG;
            } else {
                return KEY_RIGHT_X;
            }
        }
    }
    return KEY_NONE;
}